<?php
class UserSavePasswordAction extends UserAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	protected function afterConstruct()
	{
		$this->parseDtds('user','password');
	}
	
	public function execute()
	{
		$this->code	= 400;
		
		$data	= $this->getValidData();
		$oldPassword	= $data['oldpassword'];
		if($this->data['user']['password']!=md5(md5($oldPassword).$this->data['user']['secques']))
		{
			//旧密码校验错误
			$this->data['error_messages']['oldpassword']	= array('error'=>'旧的密码不正确');
		}
		if(empty($this->data['error_messages']))
		{
			C('UserService')->update($this->data['user']['id'], array('uc_password'=>$data['password'],'password'=>md5(md5($data['password']).$this->data['user']['secques'])));
			$this->code	= 200;
		}
	}
}
